package com.bsoft.gol.hcs.specialist.service.impl;

import com.bsoft.gol.hcs.clinical.service.IMedicalSkillsService;
import ctd.spring.boot.annotation.SsdevService;
import ctd.util.annotation.RpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.bsoft.gol.hcs.specialist.bean.request.ListIndexRequest;
import com.bsoft.gol.hcs.specialist.bean.response.ListIndexResponse;
import com.bsoft.gol.hcs.specialist.bean.response.ListSampleTypeResponse;
import com.bsoft.gol.hcs.specialist.bean.vo.IndexListVo;
import com.bsoft.gol.hcs.specialist.dao.LisInspectionIndexDAO;
import com.bsoft.gol.hcs.specialist.service.ILisInspectionIndexService;

import java.math.BigInteger;
import java.util.List;

/**
 * @author lixy
 * @date 2021/8/7 22:31
 */
@SsdevService("lisInspectionIndex")
public class LisInspectionIndexServiceImpl implements ILisInspectionIndexService {

    private static final Logger LOGGER = LoggerFactory.getLogger(LisInspectionIndexServiceImpl.class);


    @Autowired
    private LisInspectionIndexDAO lisInspectionIndexDAO;

    @Autowired
    private IMedicalSkillsService medicalSkillsService;

    @Override
    @RpcService
    public List<ListSampleTypeResponse> listSampleType(ListIndexRequest request) {

        return lisInspectionIndexDAO.listSampleType(request);
    }

    /**
     * 查询检验指标
     *
     * @param request
     * @return
     */
    @Override
    @RpcService
    public ListIndexResponse listIndex(ListIndexRequest request) {

        ListIndexResponse response = new ListIndexResponse();
        //查询检验指标信息
        List<IndexListVo> indexListVos = lisInspectionIndexDAO.queryListIndexList(request);
        //查询数量
        BigInteger bigInteger = lisInspectionIndexDAO.queryListIndexListTotal(request);
        response.setTotal(bigInteger.longValue());
        response.setList(indexListVos);
        return response;
    }

    @Override
    @RpcService
    public List<IndexListVo> queryListIndexList(ListIndexRequest request){
        //查询检验指标信息
        List<IndexListVo> indexListVos = lisInspectionIndexDAO.queryListIndexList(request);
        return indexListVos;
    }

    /**
     * 定时同步LIS系统同步过来的检验指标
     */
//    @Override
//    public void synLabReportItemList() {
//
//        LOGGER.info("synLabReportItemList 开始执行");
//        GetLabReportItemListReq request = new GetLabReportItemListReq();
//        request.setPageNo(1);
//        request.setPageSize(1000);
//        //获取lis检验指标
//        BaseResponse<GetLabReportItemListResponse> baseResponse = medicalSkillsService.getLabReportItemList(request);
//        if (baseResponse.getCode() == ResultCode.SUCCESS) {
//            GetLabReportItemListResponse data = baseResponse.getData();
//            saveLisInspectionIndex(data);
//
//            Integer total = data.getTotal();
//            if (total > request.getPageSize()) {
//                request.setPageSize(1000);
//
//                int tatalPageSize = (total + 1000 - 1) / 1000;
//                request.setPageNo(request.getPageNo() + 1);
//                while (request.getPageNo() <= tatalPageSize) {
//                    BaseResponse<GetLabReportItemListResponse> baseResponse1 = medicalSkillsService.getLabReportItemList(request);
//                    if (baseResponse.getCode() == ResultCode.SUCCESS) {
//                        //参数转化
//                        saveLisInspectionIndex(baseResponse1.getData());
//                    }
//                    request.setPageNo(request.getPageNo() + 1);
//                }
//
//
//            }
//        }
//        LOGGER.info("synLabReportItemList 执行结束");
//    }

    /**
     * 参数转化
     *
     * @param reportItemList
     */
//    private void saveLisInspectionIndex(GetLabReportItemListResponse reportItemList) {
//        List<GetLabReportItemListResponse.ReportItemList> reportItemLists = reportItemList.getReportItemLists();
//
//        if (CommonUtils.isNotEmpty(reportItemLists)) {
//            //将检验指标保存到数据库
//            for (GetLabReportItemListResponse.ReportItemList itemList : reportItemLists) {
//                LisInspectionIndex exit = lisInspectionIndexDAO.getFindLisInspectionIndex(itemList.getReportItemCode(), itemList.getReportItemName());
//                if (CommonUtils.isEmpty(exit)) {
//                    LisInspectionIndex lisInspectionIndex = new LisInspectionIndex();
//                    lisInspectionIndex.setIndexAbbreviation(itemList.getReportItemAbbreviation());
//                    lisInspectionIndex.setIndexCode(itemList.getReportItemCode());
//                    lisInspectionIndex.setIndexInputCode(itemList.getInputCode());
//                    lisInspectionIndex.setIndexName(itemList.getReportItemName());
//                    lisInspectionIndex.setSampleTypeCode(itemList.getSampleTypeCode());
//                    lisInspectionIndex.setSampleTypeName(itemList.getSampleTypeName());
//                    lisInspectionIndex.setStatus((byte) 1);
//                    lisInspectionIndexDAO.save(lisInspectionIndex);
//                }
//            }
//        }
//    }
}
